<?php
/**
 * @package LaravelBoot
 *
 * @internal
 *
 * @author mawenpei
 * @date 2019/3/15 1:07
 * @version
 */
namespace Modules\Api\Controllers;

use App\Models\AppControl;
use Illuminate\Http\Request;

class AppController extends Controller
{
    public function control(Request $request)
    {
        //$app_name = $request->input('app_name');
        //$app_platform = $request->input('app_platform');
        $app_channel = $request->input('app_channel');
        $app_version = $request->input('app_version');
        $info = (new AppControl())->query()->where('channel',$app_channel)->where('current_version',$app_version)->first();
        if(!$info){
            return fail('APP版本不存在');
        }

        $data = ['need_update'=>false,'force_update'=>false];
        $data['open_weixin_login'] = $info->open_weixin_login ? true : false;
        $data['download_url'] = $info->download_url;
        $data['update_words'] = $info->update_words;
        if($info->is_update || $info->force_update){
            $need_update = version_compare($app_version,$info->update_to_version) < 0 ? true : false;
            $data['need_update'] = $need_update;
            if($need_update && $info->force_update){
                $data['force_update'] = $need_update;
            }
        }

        return success($data);
    }
}